package priv.happy.mealpickpro.util;

import java.util.Random;

/**
 * @Author: HAPPY
 * @Project_name: mealPick
 * @Package_name: priv.happy.mealpick.util
 * @Date: 2023/10/10 19:11
 * @Description:
 */
public class CaptchaUtil {
    /**
     *  生成随机验证码，包含数字和字母
     * @param length 验证码长度
     * @return 返回随机验证码
     */
    public static String generateRandomCode(int length) {
        String characters = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
        Random rnd = new Random();
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < length; i++) {
            int index = rnd.nextInt(characters.length());
            sb.append(characters.charAt(index));
        }

        return sb.toString();
    }
}
